<?php
declare (strict_types=1);

namespace app\course\service\coupon;

use app\common\service\BaseService;
use app\course\logic\coupon\Coupon as CouponLogic;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Request;
use think\Response;

/**
 * 课程接口类-前台
 */
class Coupon extends BaseService
{

    /**
     * 获取课程可领取卡券
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-26
     *
     * @return Response [type]                      [description]
     */
    public function getCourseCoupon(): Response
    {
        $param = Request::get();
        $data  = app(CouponLogic::class)->getCourseCoupon($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取用户的课程卡券
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-26
     *
     * @return Response [type]                      [description]
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getUserCourseCoupon(): Response
    {
        $param = Request::get();
        $data  = app(CouponLogic::class)->getUserCourseCoupon($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取机构卡券
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-26
     *
     * @return Response [type]                      [description]
     */
    public function getSchoolCoupon(): Response
    {
        $param = Request::get();
        $data  = app(CouponLogic::class)->getSchoolCoupon($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取用户的机构卡券
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-27
     *
     * @return Response [type]                      [description]
     */
    public function getUserSchoolCoupon(): Response
    {
        $param = Request::get();
        $data  = app(CouponLogic::class)->getUserSchoolCoupon($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    // 领取卡券
    public function deriveCoupon(int $id): Response
    {
        $data = app(CouponLogic::class)->deriveCoupon($id);

        return $this->parseToData($data, 1, '领取成功');
    }

    // 兑换课程卡
    public function exchangeCourseCard(): Response
    {
        $param = Request::post();
        app(CouponLogic::class)->exchangeCourseCard($param);

        return $this->parseToData([], 1, '兑换成功');
    }
}
